#include "messageHandler.h"
#include "log/Logging.h"
#include "qlibc/QData.h"
#include "../roleLogic/observe.h"
#include <iostream>

void master_update_messageHandle(const Request &request)
{
    qlibc::QData data(request.body);
    LOG_INFO << data.toJsonString(true);
}

void all_update_messageHandle(const Request &request)
{
}

void app_site_list_update_messageHandle(const Request &request)
{
}


/**
 * {
 *      "sn": "",
 *      "role": "master/salve"
 * }
 * 
 * 
 * 
 */
void master_slave_switch_messageHandle(const Request &request)
{
    qlibc::QData data(request.body);
    string sn = data.getString("sn");
    // todo 比较sn是否相等，如果相等则执行后续逻辑
    if(sn == "abc"){
        string role = data.getString("role");
        if(role == "master"){
            Observe::getInstance()->run_master();
        }else{
            Observe::getInstance()->run_slave();
        }
    }
}
